package cn.wolfcode.shop.goodsserver.mapper;

import cn.wolfcode.shop.goodsapi.domain.Good;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface GoodsMapper {

    @SelectProvider(type = SeckillOrderQuery.class, method = "findByIds")
    List<Good> findByIds(@Param("ids") List<Long> ids);

    @Select("select * from t_goods where id = #{goodId}")
    Good findById(@Param("goodId") Long goodId);

    @Update("updata t_goods set ")
    int updataById(Long goodId);


    class SeckillOrderQuery {
        public String findByIds(@Param("ids") List<Long> ids) {
            StringBuilder str = new StringBuilder();
            str.append("select * from t_goods where id in");
            for (Long id : ids) {
                str.append("(");
                str.append(id);
                str.append(")");
            }

            return str.toString().replace(")(", ",");

        }
    }
}
